from email.mime.text import MIMEText
import smtplib
from datetime import datetime
import random




class Email_verification:
    """"""
    """邮箱验证"""
    def __init__(self, receiver):
        self.keys = "TAbHStt75U28edD5"
        self.code = str(random.randint(100000, 999999))
        self.receiver = receiver
        self.send_email_code()
    def send_email_code(self):
        mail_host = "smtp.126.com"
        mail_sender = "cy3375236591@126.com"
        mail_pwd = self.keys
        smtp = smtplib.SMTP_SSL(mail_host,  587)
        smtp.login(mail_sender, mail_pwd)

        date = datetime.now().strftime("%Y-%m-%d")
        data = MIMEText(f"{date}"
                        f"验证码：{self.code}")
        data["Subject"] = "云易购邮件验证"
        data["From"] = "cy3375236591@126.com"

        receivers = self.receiver
        data["To"] = ":".join(receivers)

        smtp.sendmail(mail_sender, receivers, data.as_string())
        smtp.quit()

